package com.qianmi.cloud.dialogue;

import com.qianmi.cloud.vo.Principal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.stereotype.Component;

/**
 * @Description 更新会话信息
 * @Date 2022-02-16 15:20
 * @Created by cai chao
 */
@Component
public class TokenStoreHandler {

    @Autowired
    private TokenStore tokenStore;

    public void storeAccessToken(String storeId) {
        OAuth2AuthenticationDetails details = SecurityUtils.getDetail();

        OAuth2AccessToken accessToken = tokenStore.readAccessToken(details.getTokenValue());
        OAuth2Authentication authentication = tokenStore.readAuthentication(accessToken);
        Principal principal = (Principal) authentication.getPrincipal();
        principal.setStoreId("修改信息店铺");
        tokenStore.storeAccessToken(accessToken, authentication);
    }
}
